package com.grupoconstruobras.sigo.general;

import com.grupoconstruobras.sigo.general.util.ManagedBeanUtils;
import com.grupoconstruobras.sigo.general.util.SijypConstants;

import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import javax.servlet.http.HttpServletRequest;

@RequestScoped
@Named
public class IndexRequestBackingBean {

  public IndexRequestBackingBean(){
    init();
  }
  
  //@PostConstruct
  public void init() {

    HttpServletRequest request = (HttpServletRequest) (FacesContext.getCurrentInstance()
                                                                   .getExternalContext().getRequest());

    String reason = request.getParameter("reason");
    if (reason != null) {
      if (reason.equals(SijypConstants.SESSION_EXPIRED)) {
        String msgTxt = ManagedBeanUtils.getMessagesBundle().getString("general.sesionExpirada");
        FacesContext.getCurrentInstance().addMessage(null,
                                                     new FacesMessage(FacesMessage.SEVERITY_WARN,
                                                                      msgTxt, null));
      }
      else if (reason.equals(SijypConstants.NOT_ALLOWED_ACCESS)) {
        String msgTxt = ManagedBeanUtils.getMessagesBundle()
                                        .getString("general.accesoNoAutorizado");
        FacesContext.getCurrentInstance().addMessage(null,
                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                      msgTxt, null));
      }
    }
  }

  public String getDummyProperty() {
    return null;
  }

  public void setDummyProperty() {

  }
}
